package jp.co.systemi.asp.workflow.approve;

import java.util.List;
import java.util.logging.Logger;

import jp.co.systemi.asp.utils.DModalWindow;
import jp.co.systemi.asp.workflow.ICallback;
import jp.co.systemi.asp.workflow.Main;
import jp.co.systemi.asp.workflow.data.Apply;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.PropertyModel;
// TODO：承認ステータスがあったり、なかったり、Panelとして、まとめるのは？
public class ApproverList extends WebPage {
    /**
     * ログ出力 クラス名をあわせること
     */
    @SuppressWarnings("unused")
    private static final Logger log = Logger.getLogger(ApproverList.class
            .getName());
    private static final long serialVersionUID = -2661434196475651991L;
    public ApproverList(final Main mainPage, final DModalWindow window) {
        init(mainPage, window);
    }

    @SuppressWarnings("unchecked")
    public void init(final Main mainPage, final DModalWindow window) {
        WebMarkupContainer tblApprovers = new WebMarkupContainer("wi_tblApprover");
        Form<?> form = new Form("wi_form");
        this.add(form);
        form.add(tblApprovers);
        List<Apply> approvers = (List<Apply>)(((ICallback)mainPage).getDefault(null));
        tblApprovers.add(new ListView<Apply>("wi_trApprover", approvers) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<Apply> item) {
                Apply user = (Apply) item.getModelObject();
                item.add(new Label("wi_tdApproverSeq", new PropertyModel<String>(user,
                        "seq")));
                item.add(new Label("wi_tdApproverRole", new PropertyModel<String>(user,
                        "role")));
                item.add(new Label("wi_tdApproverUserName", new PropertyModel<String>(
                        user, "approverName")));
                item.add(new Label("wi_tdApproverGroupName", new PropertyModel<String>(
                        user, "approverGroupName")));
                item.add(new Label("wi_tdApproverMemo", new PropertyModel<String>(
                        user, "memo")));
                item.add(new Label("wi_tdApproverStatus", new PropertyModel<String>(
                        user, "status")));

            }

        });

        form.add(new AjaxButton("wi_OK") {
            private static final long serialVersionUID = 5873629255088464587L;
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                window.setWindowClosedCallback(window.getOKActionCallback());
                window.close(target);
            }

        });
    }


}
